import axios, { AxiosRequestConfig } from 'axios'

import { IAttachmentListItem } from '../interface'
import './__mock__'

/** 获取运单附件列表 */
export const apiGetAttachmentList = async (
  waybillNo: string,
  signal?: AxiosRequestConfig['signal'],
): Promise<IAttachmentListItem[]> => {
  return axios
    .post(`/tmsapi/attach/list`, { type: 1, sourceId: waybillNo }, { signal })
    .then(res => res.$data?.attachListResultParams || [])
}

/** 修改运单附件类型 */
export const apiEditAttachmentType = async (fileId: number, fileType: number) => {
  await axios.post(`/tmsapi/waybill_record/updateWaybillAttachInfo`, { fileId, fileType })
}

/** 运单附件删除 */
export const apiDelAttachment = async (fileId: number) => {
  await axios.post(`/tmsapi/waybill_record/deleteWaybillAttach`, fileId, {
    headers: { 'Content-Type': 'application/json' },
  })
}
